<?php
namespace Admin\Controller;
use Think\Controller;

/**
 * Class LoginController
 * @package Admin\Controller
 * 登录控制器
 */

class LoginController extends Controller{
    public function index(){
        $this->display();
    }
    public function userLoginIn(){

        $username = I('post.username');
        $pwd = I('post.password');
        $user = M('Admin');
        $where['username'] =array('eq', base64_decode($username));
        $where['password'] = array('eq', md5($pwd));
        $useryesornot =  $user->where($where)->find();
        if($useryesornot){
            //设置用户名缓存
            set_module_session('admin', 'realname', $useryesornot['realname']);
            set_module_session('admin', 'user_id', $useryesornot['id']);
            set_module_session('admin', 'user_role', $useryesornot['role_id']);
            $role_model = D('Role');
            $role = $role_model->queryObj($useryesornot['role_id'], 'id');
            set_module_session('admin', 'role', $role['name']);
            set_module_session('admin', 'last_use', time());
            //登录成功
            echo json_encode(array('status'=>999));
        }else{
            echo json_encode(array('status'=>0));
        }
    }

    /**
     * @param $code
     * @param string $id
     * @return bool
     */
    function check_verify($code, $id = ''){
        $verify = new \Think\Verify();
        return $verify->check($code, $id);
    }


    public function loginOut(){
        destory_module_session('admin');
        $this->display("index");
    }
}